package com.example.design.patterns.geekbang.行为型.职责链模式.中途停止.实现方式二;

import java.util.ArrayList;
import java.util.List;

/**
 * HandlerChain 是处理器链
 * 数据结构：数组
 */
public class HandlerChain {
    private List<IHandler> handlers = new ArrayList<>();

    public void addHandler(IHandler handler) {
        this.handlers.add(handler);
    }

    public void handle() {
        for (IHandler handler : handlers) {
            boolean handled = handler.handle();
            if (handled) {
                break;
            }
        }
    }
}
